import type { ResponseData } from '@/utils/request';
import { SUCCESS_CODE } from '@/utils/request';
import type { RequestData } from '@ant-design/pro-table';
import { message } from 'antd';
import { request, useModel } from 'umi';
import type { orderList, QueryParams } from './types';

//查询单个数据
export async function getOrderDetail(id?: string) {
  return await request(`/parking/${id}`);
}

//订单列表
export async function getOrderTable(params: QueryParams): Promise<RequestData<orderList>> {
  return await request('/parking/pageQueryList', {
    params: {
      ...params,
      page: params.current,
      pageSize: params.pageSize,
      // beginTime   endTime
      startArrivedDate: params.beginTime && params.beginTime[0],
      endArrivedDate: params.beginTime && params.beginTime[1],
      startLeaveDate: params.endTime && params.endTime[0],
      endLeaveDate: params.endTime && params.endTime[1],

      // tenant_id: params.tenant ? params.tenant?.id : '',
    },
  });
}

//结束停车
export async function overPark(id: string, end_time: string): Promise<RequestData<never>> {
  return await request(`/parking/${id}/stop`, {
    method: 'POST',
    data: {
      end_time,
    },
  });
}

//退款接口
export async function parkRefund(params: {
  orderNo: string;
  refundAmount: string;
  refundReason: string;
  refundUserPhone: string;
}): Promise<RequestData<never>> {
  return await request(`/parking/refund`, {
    method: 'POST',
    data: {
      ...params,
    },
  });
}
